<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>计算属性，方法，侦听器</title>
  <script src="../asset/js/vue.js"></script>
</head>

<body>
  <div id="app">
    <div>{{fullName}}</div>
    <div>{{age}}</div>
  </div>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        firstName: 'Xu',
        lastName: 'ZiYu',
        fullName: 'Xu ZiYu',
        age: 32
      },
      // 计算属性，如果依赖的值没有改变，就不会更新（缓存）
      /* computed: {
        fullName() {
          console.log('计算了一次')
          return `${this.firstName} ${this.lastName}`
        }
      }, */
      /* methods: {
        fullName() {
          console.log('计算了一次')
          return `${this.firstName} ${this.lastName}`
        }
      }, */
      watch: {
        firstName: function () {
          console.log('计算了一次')
          this.fullName = `${this.firstName} ${this.lastName}`
        },
        lastName: function () {
          console.log('计算了一次')
          this.fullName = `${this.firstName} ${this.lastName}`
        }
      }
    })
  </script>
</body>

</html>